#include "WProgram.h"
/*  10\u00ba, 90\u00ba, 170\u00ba
    Moves servo to 3 different angles
    with a pause of 1 second each.
*/
 
void setup();
void servoPulse(int servoPin, int myAngle);
void loop();
int servoPin = 9;   // servo connected to digital pin 2
int myAngle;	  // angle of the servo roughly 0-180
int pulseWidth;     // servoPulse function variable
 
void setup()
{
  pinMode(servoPin, OUTPUT);   // sets pin 2 as output
}
 
void servoPulse(int servoPin, int myAngle)    
{	
  pulseWidth = (myAngle * 10) + 1200;  // determines delay  
  digitalWrite(servoPin, HIGH);	 // set servo high
  delayMicroseconds(pulseWidth);	// micro pause
  digitalWrite(servoPin, LOW);	  // set servo low
  delay(20);				  // refresh cycle
}
 
void loop()
{

  myAngle = 0;			     // starts at 10\u00ba

  for(int i=0; i<50; i++)		 // loops 50 times
  {
    servoPulse(servoPin, myAngle);
  }

  delay(3000);
  myAngle = 270;			     // moves to 90\u00ba

  for(int i=0; i<50; i++)		 // loops 50 times
  {
    servoPulse(servoPin, myAngle);
  }
 delay(3000);
  myAngle = 360;			    // then moves to 170\u00ba

  for(int i=0; i<50; i++)		 // loops 50 times
  {
    servoPulse(servoPin, myAngle);
  }
  delay(3000);
} 


int main(void)
{
	init();

	setup();
    
	for (;;)
		loop();
        
	return 0;
}

